import 'package:boss/models/cloud_printer.dart';
import 'package:boss/provider/cloud_printer_provider.dart';
import 'package:boss/ui/widget/alert/alert.dart';
import 'package:boss/ui/widget/back_confirmation.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:provider/provider.dart';
import 'package:router/annotation.dart';

import 'widget/printer_step_one_browser.dart';

@RouterConfig(PrinterStepOnePage.pageName)
class PrinterStepOnePage extends StatefulWidget {
  static const pageName = '/printerStepOnePage';

  @Autowired()
  final int id;

  const PrinterStepOnePage({this.id});

  @override
  _PrinterStepOnePageState createState() => _PrinterStepOnePageState('新增打印机');
}

class _PrinterStepOnePageState extends BaseState<PrinterStepOnePage> {
  _PrinterStepOnePageState(String pageName) : super(pageName);

  @override
  void initState() {
    super.initState();
    var provider = Provider.of<CloudPrinterProvider>(
      context,
      listen: false,
    );
    provider.isEdit = widget.id != null;

    if (!provider.isEdit) {
      provider.editCloudPrinter = CloudPrinter.fromJson({});
    }
  }

  @override
  Widget build(BuildContext context) {
    return BackConfirmation(
      backConfirmationText: '打印机还未完成确认返回么？',
      child: Scaffold(
        appBar: CenterTitleAppBar(
          title: '${widget.id == null ? '新增' : '修改'}打印机',
          backConfirmationText: '打印机还未完成确认返回么？',
        ),
        body: PrinterStepOneBrowser(),
      ),
    );
  }
}
